package cn.south.campus.business.model.vo;

import cn.south.campus.business.model.entity.ComplaintComment;
import cn.south.campus.common.model.vo.BaseVO;
import cn.south.campus.common.utils.DateUtil;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author chow
 * @since 2025/1/16 17:12
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class ComplaintCommentVo extends BaseVO {
    /**
     * 图片
     */
    private String pic;

    /**
     * 内容
     */
    private String content;

    /**
     * 点赞数
     */
    private Long agreeCount = 0L;

    /**
     * 是否点赞
     */
    private boolean agree;

    /**
     * 评论数
     */
    private Long commentCount;

    /**
     * 吐槽id
     */
    private Long complaintId;

    /**
     * 父id
     */
    @JsonProperty("pId")
    private Long pId;

    @JsonProperty("pNickname")
    private String pNickname;

    /**
     * 祖先id
     */
    private Long ancestor;

    /**
     * 用户id
     */
    private Long userId;

    /**
     * 用户头像
     */
    private String avatar;

    /**
     * 用户昵称
     */
    private String nickname;

    /**
     * 评论时间
     */
    private String timeAgo;

    /**
     * 子评论总数
     */
    private Long subCommentsTotal;

    /**
     * 子评论
     */
    private List<ComplaintCommentVo> children;


    public static ComplaintComment convert(ComplaintCommentVo vo) {
        if (vo == null) {
            return null;
        }
        ComplaintComment complaintComment = new ComplaintComment();
        complaintComment.setPic(vo.getPic());
        complaintComment.setContent(vo.getContent());
        complaintComment.setPId(vo.getPId());
        complaintComment.setPNickname(vo.getPNickname());
        complaintComment.setAncestor(vo.getAncestor());
        complaintComment.setComplaintId(vo.getComplaintId());
        complaintComment.setId(vo.getId());
        complaintComment.setUserId(vo.getUserId());
        return complaintComment;
    }

    public static ComplaintCommentVo convert(ComplaintComment complaintComment) {
        if (complaintComment == null) {
            return null;
        }
        ComplaintCommentVo vo = new ComplaintCommentVo();
        vo.setPic(complaintComment.getPic());
        vo.setContent(complaintComment.getContent());
        vo.setPId(complaintComment.getPId());
        vo.setPNickname(complaintComment.getPNickname());
        vo.setId(complaintComment.getId());
        vo.setAncestor(complaintComment.getAncestor());
        vo.setUserId(complaintComment.getUserId());
        vo.setAvatar(complaintComment.getAvatar());
        vo.setNickname(complaintComment.getNickname());
        vo.setTimeAgo(DateUtil.getTimeAgo(complaintComment.getUpdateTime()));
        vo.setCreateTime(DateUtil.format(complaintComment.getCreateTime()));
        vo.setUpdateTime(DateUtil.format(complaintComment.getUpdateTime()));
        return vo;
    }
}
